package com.school.service.impl;

import com.school.dao.CourseDao;
import com.school.dao.GradeDao;
import com.school.dao.TeacherDao;
import com.school.dao.impl.CourseDaoImpl;
import com.school.dao.impl.GradeDaoImpl;
import com.school.dao.impl.TeacherDaoImpl;
import com.school.domain.Course;
import com.school.domain.Grade;
import com.school.domain.Teacher;
import com.school.service.TeacherService;

import java.util.List;

public class TeacherServiceImpl implements TeacherService {
    private final TeacherDao teacherDao = new TeacherDaoImpl();
    private final CourseDao courseDao = new CourseDaoImpl();
    private final GradeDao gradeDao = new GradeDaoImpl();

    @Override
    public boolean teacherLogin(long tid, String pwd) {
        Teacher teacher = teacherDao.findById(tid);
        return teacher != null && teacher.getPwd().equals(pwd);
    }

    @Override
    public Teacher findById(long tid) {
        return teacherDao.findById(tid);
    }

    @Override
    public boolean update(Teacher teacher) {
        return teacherDao.update(teacher);
    }

    @Override
    public boolean addCourse(Course course) {
        return courseDao.add(course);
    }

    @Override
    public List<Course> findCourses(long tid) {
        return courseDao.findByTid(tid);
    }

    @Override
    public boolean addGrade(Grade grade) {
        return gradeDao.addGrade(grade);
    }

    @Override
    public boolean updateCourse(Course course) {
        return courseDao.update(course);
    }

    @Override
    public Course findCourse(long coid) {
        return courseDao.findById(coid);
    }
}
